<?php
class UserController extends ManagerController {
	public function UserController(){
		parent::ManagerController();
	}
	
	public function index(){
		$user_mod = new UserModel();
		$this->init_page_info(20);
		$condition = array('site_id'=>SITE_ID);
		$total = $user_mod->count($condition);
		$this->set_page_total($total);
		$users = $user_mod->find($condition, null, $this->page_info->get_start(), $this->page_info->page_size);
		$this->assign('users', $users);
		$this->display();
	}
	
	public function edit(){
		if(IS_POST){
			$this->save();
		}
		$this->display();
	}
	
	private function save(){
		$h = new FormHelper(array(
			'name' => 'user_edit',
			'add_site_id' => true,//自动 添加site_id
		));
		$result = $h->get_post_data();
		if($result['result'] === false){
			$this->ajax_info($result);
		}
		if(!empty($this->id)){
			//修改
			$result['data']['_id'] = $this->id;
			$result = UCenter::update_user_info($result['data']);
		}else{
			$result = UCenter::add_user($result['data']);
		}
		
		$this->ajax_info($result);
	}
	
	public function del(){
		$result = UCenter::delete_user($this->id, SITE_ID);
		$this->ajax_info($result);
	}
}

?>